# pi.comet
# http://pi.kodfabrik.com
# developer: azer koculu <http://azer.kodfabrik.com>

class PIComet:
	
	def __init__(self,method=1,name="PIComet"):
		self.method = method
		self.contentType = [
			"text/html",
			"application/x-dom-event-stream",
			"text/html"
		][int(self.method)-1]
		self.name = name
		self.null = [
			"",
			"<comet></comet>"
		][int(self.method==3)]
	
	def push(self,text):
		result = [
			"<comet>%s</comet>"%text,
			"Event: %s\ndata:%s\n\n"%(self.name,text),
			"<script>parent.PIComet.event.push(\"%s\")</script>"%(text)
		][int(self.method)-1]
		return result
